home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-05-08 | 1.9 KB | 57 lines | [TEXT/CWIE] |
- // Program Author: Paul Baxter
- // pbaxter@assistivetech.com
- //
- //
-
-
- #include "aeutils.h"
- #include "aetoken.h"
- #include "aeaccessors.h"
- #include "aecoercions.h"
-
- // * ****************************************************************************** *
- // * InstallCoercions
- // * Install AppleEvent Coercions
- // * ****************************************************************************** *
- OSErr InstallCoercions(void)
- {
- OSErr err;
-
- err = AEInstallCoercionHandler(typeObjectSpecifier, typeNull, (AECoercionHandlerUPP)NewAECoerceDescProc(CoerceObjToAnything), 0, true, false);
- err = AEInstallCoercionHandler(typeObjectSpecifier, typeMyApplProp, (AECoercionHandlerUPP)NewAECoerceDescProc(CoerceObjToAnything), 0, true, false);
- err = AEInstallCoercionHandler(typeObjectSpecifier, typeMyAppl, (AECoercionHandlerUPP)NewAECoerceDescProc(CoerceObjToAnything), 0, true, false);
- return(err);
- }
-
- // * ****************************************************************************** *
- // * CoerceObjToAnything
- // * Takes an object specifier that it resolves using AEResolve
- // * then tries to coerce this result into the type specified by toType
- // * ****************************************************************************** *
- pascal OSErr CoerceObjToAnything(const AEDesc *theAEDesc,
- DescType toType,
- long handlerRefCon,
- AEDesc *result)
- {
- #pragma unused (handlerRefCon)
-
- AEDesc objDesc = {typeNull, NULL};
- OSErr err;
-
- if (theAEDesc->descriptorType != typeObjectSpecifier)
- return(errAEWrongDataType);
-
- // resolve the object specifier
- err = AEResolve(theAEDesc, kAEIDoMinimum, &objDesc);
- if (noErr != err) goto done;
-
- // hopefully it's the right type by now, but we'll give it a nudge
- err = AECoerceDesc(&objDesc, toType, result);
-
- done:
- if (objDesc.dataHandle)
- AEDisposeDesc(&objDesc);
-
- return(err);
- } // CoerceObjToAnything
-